/*******************************************************************************
 *
 *    Copyright (c) Baina Info Tech Co. Ltd
 *
 *    Purse
 *    
 *    ShareperfrenceManager
 *    TODO File description or class description.
 *
 *    @author: zuochen
 *    @since:  2010-11-19
 *    @version: 1.0
 *
 ******************************************************************************/

package com.tool.finance.manager;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.tool.finances.lifestyle.UnitSetting;

/**
 * ShareperfrenceManager of Purse.
 * 
 * @author zuochen
 * 
 */

public class ShareperfrenceManager {
	Context mContext;
	SharedPreferences mPreferences;
	static final String IS_NEED_PASSWORD = "is_need_password";

	/**
	 * Initiate a new instance of {@link ShareperfrenceManager}.
	 * 
	 * @param mContextApication
	 *            上下文
	 */
	public ShareperfrenceManager(Context mContext) {
		this.mContext = mContext;
		// mPreferences =
		// PreferenceManager.getDefaultSharedPreferences(mContext);

	}

	/**
	 * Get the password's state
	 * 
	 * @return true when password need.
	 */
	public int getPasswordSate() {

		mPreferences = mContext.getSharedPreferences("setpassword",
				Context.MODE_PRIVATE);
		int bools = mPreferences.getInt("ishaspassword", 1);
		return bools;
	}

	/**
	 * Save the password state.
	 * 
	 * @param isNeddPassword
	 *            whether the password need.
	 */
	public void savePasswordState(boolean isNeddPassword) {
		mPreferences.edit().putBoolean(IS_NEED_PASSWORD, isNeddPassword);
	}

	public String getUnit() {
		mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
		return mPreferences.getString(UnitSetting.UNIT, "$");
	}

	public void saveUnit(String unit) {
		mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
		mPreferences.edit().putString(UnitSetting.UNIT, unit).commit();
	}
}
